package com.lagou.edu.factory;

import com.lagou.edu.utils.DruidUtils;

import java.sql.Connection;
import java.sql.SQLException;

public class ConnectionFactory {

    private static final ThreadLocal<Connection> connectionThreadLocal = new ThreadLocal<>();

    public static Connection getConnection() throws SQLException {
        Connection connection = connectionThreadLocal.get();
        if (connection == null) {
            connection = DruidUtils.getInstance().getConnection();
            connectionThreadLocal.set(connection);
        }
        return connection;
    }

    private ConnectionFactory(){}
}
